# -!- coding: utf-8 -!-
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#作者：cacho_37967865
#博客：https://blog.csdn.net/sinat_37967865
#文件：get_stock_top.py
#日期：2020-08-11
#备注：获取涨停股票信息:http://wuylh.com/replayrobot/wylh2020-8-11p.html,
      存入到数据库stock_top，topInfo_to_mysql()    
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

import requests
import re
from bs4 import BeautifulSoup
from pacong.stock.stock_config import db,cursor,headers
from pycacho.cachobase.logger import Logger


logger = Logger("get_stock_top").get_log()


# 获取连板股信息
def get_lbInfo(date):
    url = 'http://wuylh.com/replayrobot/wylh{0}p.html'.format(date)     # 2020-8-11
    resp = requests.get(url, headers=headers)
    logger.info('爬取的龙虎榜上榜信息为：%s', url)
    resp.encoding = 'utf-8'
    data = resp.text
    h2 = re.findall(r'<h2>(.*)</span></h2>', data)
    for info in  h2:
        remark = info.replace('<span style="margin-left: 15px; font-size: 0.8em;">','')
        print(remark)

# 获取连板股信息
def get_lbInfo1(date):
    url = 'http://wuylh.com/replayrobot/wylh{0}p.html'.format(date)     # 2020-8-11
    resp = requests.get(url, headers=headers)
    logger.info('爬取的龙虎榜上榜信息为：%s', url)
    resp.encoding = 'utf-8'
    data = resp.text
    soup = BeautifulSoup(data, 'html5lib')  # "lxml"解析器丢失数据
    print(soup.h2.get_text())
    #print(h2)


if __name__ == '__main__':
    get_lbInfo('2020-8-19')